# -*- coding: utf-8 -*-
import KBEngine
from KBEDebug import *
import d_server
import time

class Shield:
    def __init__(self):
        pass

    def addShieldInvite(self, dbid, nickName, avatarUrl):
        #增加一个邀请人
        inviteInfo = {
            "dbid": dbid,
            "nickName": nickName,
            "avatarUrl": avatarUrl
        }
        self.shieldInviteList.append(inviteInfo)
        self.shieldInviteList = self.shieldInviteList

    def openShield(self):
        #激活护盾
        if self.shieldIsOpen != 0:
            self.promptClient("ShieldHadOpen")
            return 1
        if len(self.shieldInviteList) < d_server.ShieldInviteNum:
            self.promptClient("InviteNumLess")
            return 1
        self.shieldIsOpen = 1
        self.client.onOpenShield()
        self.updateToWatcher(d_server.UpdateType.OpenShield, {})

    def addShieldTime(self, addSeconds):
        #增加护盾时间
        if addSeconds > 0:
            curTime = int(time.time())
            if self.shieldEndTime < curTime:
                self.shieldEndTime = curTime
            self.shieldEndTime += addSeconds
            self.updateToWatcher(d_server.UpdateType.AddShieldTime, {})

    def isShieldOpened(self):
        if 0 == self.shieldIsOpen:
            return False
        else:
            return True

    def isShielding(self):
        #当前是否处于保护中
        if 1 == self.shieldIsOpen:
            curTime = int(time.time())
            if self.shieldEndTime > curTime:
                return True
        return False